//
//  SMHProfitNumberView.swift
//  SMHCommerce
//
//  Created by lvzhao on 2020/5/10.
//  Copyright © 2020 lvzhao. All rights reserved.
//

import UIKit
import SwiftyFitsize

class SMHProfitNumberView: LZBaseView {
    
    
    var amountLab = Array<UILabel>()
    
    override init(viewModel: LZBaseViewModel) {
        super.init(viewModel: viewModel)
        
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    //MARK: 初始化UI
    func setupUI() {
        
        let number = "0,000,000,000"
        var lastView = UIView()
        for (index,item) in number.enumerated() {
            if item == "0" {
                //创建label
                let numberLab = UILabel()
                numberLab.backgroundColor = UIColor.white
                numberLab.layer.cornerRadius = 2
                numberLab.textAlignment = .center
                numberLab.clipsToBounds = true
                numberLab.textColor = UIColorFromHex(rgbValue: 0xFF661B)
                numberLab.font = ktextBoldFont(size: 30)~
                self.addSubview(numberLab)
                numberLab.snp.makeConstraints { (make) in
                    if index == 0 {
                        make.left.equalTo(0)
                    } else {
                        if lastView is UILabel {
                            make.left.equalTo(lastView.snp.right).offset(2)
                        } else {
                            make.left.equalTo(lastView.snp.right).offset(0.5)
                        }
                    }
                    make.top.equalTo(0)
                    make.width.equalTo(22)
                    make.height.equalTo(30)
                }
                lastView = numberLab
                amountLab.append(numberLab)
            } else {
                //创建imageview,
                let imageView = UIImageView.init(image: UIImage.init(named: "icon_profit_douhao"))
                self.addSubview(imageView)
                imageView.snp.makeConstraints { (make) in
                    make.left.equalTo(lastView.snp.right)
                    make.width.equalTo(6)
                    make.height.equalTo(9)
                    make.bottom.equalTo(0)
                }

                lastView = imageView
            }

        }
        
        
    }
    
    
}
